package com.shenfc.fxzj;

import com.shenfc.fxzj.shiro.RedisCacheManager;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
//import org.springframework.cloud.client.loadbalancer.LoadBalanced;
//import org.springframework.cloud.netflix.feign.EnableFeignClients;
//import org.springframework.cloud.netflix.hystrix.EnableHystrix;
//import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;

@SpringBootApplication
@MapperScan("com.shenfc.fxzj.mapper")
@EnableScheduling
@EnableAsync
//@EnableDiscoveryClient
//@EnableFeignClients
//@EnableHystrix
//@EnableHystrixDashboard
//@EnableCircuitBreaker
//@ImportResource({ "classpath:conf/*-beans.xml" })
public class FxzjApplication extends SpringBootServletInitializer {

    @Autowired
    private RedisTemplate redisTemplate;

//    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    //    static {
//        try {
//            // 初始化log4j
//            String log4jPath = "";
//            // 日志路径
//            log4jPath = DemoApplication.class.getClassLoader().getResource("").getPath() + "log4j.properties";
//            logger.info("Log4j初始化。。。");
//            logger.info("log4j路径是 " + log4jPath);
//            PropertyConfigurator.configure(log4jPath);
//        } catch (Exception e) {
//            logger.error(e.toString());
//        }
//    }

    public static void main(String[] args) {
        SpringApplication.run(FxzjApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(FxzjApplication.class);
    }

    /**
      init
     */
    @PostConstruct
    public void init() {
        initRedisTemplate();
    }

    private void initRedisTemplate() {
        StringRedisSerializer stringRedisSerializer=new StringRedisSerializer();
        redisTemplate.setKeySerializer(stringRedisSerializer);
        redisTemplate.setValueSerializer(stringRedisSerializer);
        redisTemplate.setHashKeySerializer(stringRedisSerializer);
        redisTemplate.setHashValueSerializer(stringRedisSerializer);
    }

//    @Bean
//    @LoadBalanced
//    RestTemplate restTemplate() {
//        return new RestTemplate();
//    }
}
